$(function(){
	var showXzzxTime = 0;//30秒一次
	var showXzzxMaxTime = 30;//30秒一次
	var booleanShowXzzx = true;//是否显示现在咨询
	
	bindEvents();
	
	doEvents();
	
	//绑定事件
	function bindEvents(){
		//留言弹框
		bindToMin();
		function bindToMin(){
			$(".nb-nodeboard-close").click(function(){
				$(".nb-nodeboard-close").unbind();
				$(".nb-nodeboard-close").addClass("nb-nodeboard-max");
				$("#nb_nodeboard_text").hide();
				$("#nb_nodeboard_set").hide();
				$("#nb_node_contain").hide();
				$("#nb_nodeboard").css("top","auto");
				$("#nb_nodeboard").css("left","1px");
				$("#nb_nodeboard").css("margin-left","-0px");
				$("#nb_nodeboard").css("margin-top","-0px");
				$("#nb_nodeboard").css("height","auto");
				booleanShowXzzx = true;
				bindToMax();
			});
		}
		function bindToMax(){
			$(".nb-nodeboard-max").click(function(){
				$(".nb-nodeboard-max").unbind();
				$(".nb-nodeboard-close").removeClass("nb-nodeboard-max");
				$("#nb_nodeboard_text").show();
				$("#nb_nodeboard_set").show();
				$("#nb_node_contain").show();
				booleanShowXzzx = true;
				bindToMin();
			});
		}
		
		//咨询热线
		bindCloseZxrx();
		bindOpenZxrx();
		function bindCloseZxrx(){
			$(".lxb-hide-btn").click(function(){
				$("#LXB_CONTAINER").hide();
				$("#LXB_CLOSE_BTN").show();
			});
		}
		
		function bindOpenZxrx(){
			$("#LXB_CLOSE_BTN").click(function(){
				$("#LXB_CLOSE_BTN").hide();
				$("#LXB_CONTAINER").show();
			});
		}
		
		//现在咨询
		bindXzzx();
		function bindXzzx(){
			$("#nb_icon_wrap").click(function(){
				$(".nb-nodeboard-max").click();
				$("#nb_nodeboard").css("top","50%");
				$("#nb_nodeboard").css("left","50%");
				$("#nb_nodeboard").css("margin-left","-120px");
				$("#nb_nodeboard").css("margin-top","-185px");
				$("#nb_nodeboard").css("height","370px");
				$("#nb_nodeboard").css("right","auto");
				booleanShowXzzx = false;
				showXzzxTime = 0;
			});
			
			$("#nb_invite_tool").click(function(){
				$("#nb_invite_wrap").hide();
				showXzzxTime = 0;
				showInviteWrap();
			});
			$("#nb_invite_cancel").click(function(){
				$("#nb_invite_wrap").hide();
				showXzzxTime = 0;
				showInviteWrap();
			});
			$("#nb_invite_ok").click(function(){
				$("#nb_invite_tool").click();
				$("#nb_icon_wrap").click();
			});
		}
		
		//电话咨询
		/*setTimeout(function(){
			$("#LXB_CONTAINER").show();
		},5000);*/
		
		//显示现在咨询
		showInviteWrap();
		function showInviteWrap(){
			doCheckInvite();
			function doCheckInvite(){
				setTimeout(function(){
					if(showXzzxTime == showXzzxMaxTime){
						$("#nb_invite_wrap").show();
						showXzzxTime = 0;
					}else{
						doCheckInvite();
						if(booleanShowXzzx){
							showXzzxTime++;
						}
					}
				},1000);
			}
		}
	}
	
	function doEvents(){
		var pageIndex = $("#pageIndex").val();
		$($("#dhul").find("li")[pageIndex]).addClass("onpli");
		$(".pli").mouseover(function(){
			$(this).addClass("onpli");
		});
		$(".pli").mouseleave(function(){
			$(this).removeClass("onpli");
			$($("#dhul").find("li")[pageIndex]).addClass("onpli");
		});
	}
	
	$("#nb_nodeboard_send").click(function(){
		submitLeavingMessage();
	});
	
	//发送留言
	function submitLeavingMessage(){
		var name = $("#tname").val();
		var phone = $("#tphone").val();
		var wechatNum = $("#twechatNum").val();
		var content = $("#tcontent").val();
		if(null == name || "" == name){
			return;
		}
		if(null == phone || "" == phone){
			return;
		}
		if(null == content || "" == content){
			return;
		}
		$.ajax({
			url : ctx + "/web/jnyz/saveLeavingMessage",
			type : "post",
			data : {
				name : name,
				phone : phone,
				wechatNum : wechatNum,
				content : content
			},
			success : function(data){
				if(data.success){
					$("#tname").val("");
					$("#tphone").val("");
					$("#twechatNum").val("");
					$("#tcontent").val("");
					alert("感谢您的留言！我们将及时给您回复！");
				}else{
					alert("提交失败");
				}
			}
		});
	}
});